using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data;

namespace DataAccessLayer
{
    public class Doctor
    {
        private int regNo;
        private string name;
        private string email;
        private string password;
        private string gender;
        private string dob;
        private string specialization;
        private string degree;
        private string connstring;

        public Doctor(string connstring)
        {
            this.connstring = connstring;
        }
        public int REGNO
        {
            get { return regNo; }
            set { regNo = value; }
        }
        public string NAME
        {
            get { return name; }
            set { name = value; }
        }
        public string EMAIL
        {
            get { return email; }
            set { email = value; }
        }
        public string PASSWORD
        {
            get { return password; }
            set { password = value; }
        }
        public string DOB
        {
            get { return dob; }
            set { dob = value; }
        }
        public string GENDER
        {
            get { return gender; }
            set { gender = value; }
        }
        public string SPECIAL
        {
            get { return specialization; }
            set { specialization = value; }
        }
        public string DEGREE
        {
            get { return degree; }
            set { degree = value; }
        }
        public void funcRegistration()
        {
            SqlConnection con = new SqlConnection(connstring);
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "sp_doctor_registration";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@RegNo", regNo));
            cmd.Parameters.Add(new SqlParameter("@Name", name));
            cmd.Parameters.Add(new SqlParameter("@Email", email));
            cmd.Parameters.Add(new SqlParameter("@Password", password));
            cmd.Parameters.Add(new SqlParameter("@Dob", dob));
            cmd.Parameters.Add(new SqlParameter("@Gender", gender));
            cmd.Parameters.Add(new SqlParameter("@Spl", specialization));
            cmd.Parameters.Add(new SqlParameter("@degree", degree));
            cmd.ExecuteNonQuery();
            con.Close();
        }
        public int funcVerification(int regId)
        {
            int k = 0;

            SqlConnection objCon = new SqlConnection(connstring);
            objCon.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from Doctors", objCon);
            DataSet ds = new DataSet();
            ds.Clear();
            da.Fill(ds);
            int i = ds.Tables[0].Rows.Count;

            for (int j = 0; j < i; j++)
            {
                if (regId.ToString() == ds.Tables[0].Rows[j]["RegNo"].ToString())
                {
                    k = 1;
                    break;
                }
            }
            return k;
        }
        public bool login()
        {
            bool k = false;
            SqlConnection con = new SqlConnection(connstring);
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from Doctors ", con);
            DataSet ds = new DataSet();
            ds.Clear();
            da.Fill(ds);
            int i = ds.Tables[0].Rows.Count;
            for (int j = 0; j < i; j++)
            {
               if (regNo == Convert.ToInt32(ds.Tables[0].Rows[j]["RegNo"].ToString()) && password == ds.Tables[0].Rows[j]["Password"].ToString())
               {
                   k = true;
               }
            }
            return k;
        }
        public DataTable Dshow()
        {
            SqlDataReader s1 = null;
            SqlConnection con = new SqlConnection(connstring);
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "Dshow";
            cmd.CommandType = CommandType.StoredProcedure;
            s1 = cmd.ExecuteReader();
            DataTable dtDisplay = new DataTable();
            dtDisplay.Load(s1);
            con.Close();
            return dtDisplay;
        }
        public DataTable LoadSpecialization()
        {
            SqlDataReader s1 = null;
            SqlConnection con = new SqlConnection(connstring);
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "sp_load_specialization";
            cmd.CommandType = CommandType.StoredProcedure;
            s1 = cmd.ExecuteReader();
            DataTable dtDisplay = new DataTable();
            dtDisplay.Load(s1);

            con.Close();
            return dtDisplay;
        }
        public DataTable Dloading()
        {
            SqlDataReader s1 = null;
            SqlConnection con = new SqlConnection(connstring);
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "sp_loading_doctor";
            cmd.CommandType = CommandType.StoredProcedure;
            s1 = cmd.ExecuteReader();
            DataTable dtDisplay = new DataTable();
            dtDisplay.Load(s1);

            con.Close();
            return dtDisplay;
        }
    }
}
